<template>
  <div>
    <el-select
      v-model="selectvalue"
      filterable
      remote
      placeholder="请输入姓名"
      :remote-method="remoteMethod"
      :loading="loading"
      :style="rsustyles"
      @change="getselect"
    >
      <el-option
        v-for="item in options"
        :key="item.key"
        :label="item.label"
        :value="item"
      >
      </el-option>
    </el-select>
  </div>
</template>

<script>
export default {
  props: ["rsustyles"],
  data() {
    return {
      selectvalue:[],
      postvalue: [], //推送人
      userid:[],
      username:[],
      options: [],
      value: [],
      list: [],
      loading: false,
      states: [],
    };
  },

  methods: {
    getselect(val){
      this.postvalue=val.value
      this.userid=val.key
      this.username=val.label
    },

    setuser(userid){
      this.postvalue=[userid]
    },


    remoteMethod(query) {
      this.getuserinfonamelike(query);
      if (query !== "") {
        this.loading = true;
        setTimeout(() => {
          this.loading = false;
          this.options = this.list.filter((item) => {
            return item.label.toLowerCase().indexOf(query.toLowerCase()) > -1;
          });
        }, 200);
      } else {
        this.options = [];
      }
    },

    async getuserinfonamelike(query) {
      try {
        let res = await this.$axios.get(
          `api/member/getuserinfobynamelike?name=` + query
        );
        this.list = res.data;
      } catch (e) {}
    },
  },
};
</script>

<style lang="scss" scoped>
</style>